<template>
  <div class="app-container">
    <div class="filter-container search_Top">
        <div class="search_input_list">
          <div class="filter-item">
            <el-input clearable  v-model="searchParam.name" placeholder="姓名"
                      size="mini"
                      @keyup.enter.native="getList" />
          </div>
          <div class="filter-item">
            <el-date-picker v-model="searchParam.startTime" placeholder="开始时间"
                            size="mini"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            style="width: 140px;">
            </el-date-picker>
            <span class="date_splite"></span>
            <el-date-picker v-model="searchParam.endTime" placeholder="结束时间"
                            size="mini"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            style="width: 140px;">
            </el-date-picker>
          </div>
        </div>
        <div class="filter-item filter-item-btn-search search_bt_list">
            <span class="gosearch" @click="getList">搜索</span>
            <span class="clears" @click="clearList">清除</span>
        </div>
    </div>
    <div class="table_base_bt">
        <el-button class="filter-btn-item" v-if="hasRole('log:system:delete')"
                    size="mini"
                    type="danger"
                    icon="el-icon-delete" @click="batchDelete"
                    >删除</el-button>
    </div>
    <drug-table @getSelection="getSelection" :isMultipleSelection="true" :tableData="tableData" :tableLoading="tableLoading" :tableHeader="tableHeader" :option="option">
      <template slot-scope="props" slot="operate">
        <div >
          <label @click="handleDeleteSingle(props.rowData)" v-if="hasRole('log:system:delete')"
                 class="table-view" style="cursor: pointer;">
            删除
          </label>
        </div>
      </template>
    </drug-table>

  </div>
</template>

<script>
// import { fetchList, fetchPv, createArticle, updateArticle } from '@/api/article'
import waves from '@/views/directive/waves' // waves directive
import drugTable from "@/components/table/index";


export default {
  components: { drugTable },
  directives: { waves },
  data() {
    return {
      tableData: [],
      tableHeader:[],
      tableLoading:true,
      option:{showOperate:true},
      searchParam:{startTime:"",endTime:"",name:""},
      selectChoice:[]
    }
  },
  mounted() {
    let self = this;
    self.getList();
    self.$eventBus.$on("gteLogsList",function () {
       self.getList();
    })
  },
  methods: {
    getList() {
      let self = this;
      self.tableLoading = true;
      let searchParam = Object.assign({},this.searchParam);
      if(searchParam.endTime){
        searchParam.endTime = searchParam.endTime+" 23:59:59";
      }
      self.$http({
        url: "/drug/log/queryLogList",
        method: "post",
        params:searchParam
      }).then(resp => {
        if (resp.success) {
          self.tableLoading = false;
          self.tableData = resp.result;
          self.tableHeader =  [{"columnName": "createTimeFt", "coloumNameCn": "时间","width":"150px"},
            {"columnName": "userName", "coloumNameCn": "姓名"},
            {"columnName": "type", "coloumNameCn": "类型","width":"100px"},
            {"columnName": "detail", "coloumNameCn": "详情"}];
          self.option.showOperate = true;
        }
      });
    },
    clearList(){
      let self = this;
      for(let key in self.searchParam){
        self.searchParam[key] = "";
      }
      self.getList()
    },
    getSelection(val){
      this.selectChoice = val;
    },

    handleDeleteSingle(rowData){
      let ids = [];
      ids.push(rowData.id);
      this.handleDelete(ids);
    },

    batchDelete(){
      let self = this;
      let ids = [];
      if(!this.selectChoice || self.selectChoice.length < 1){
        self.$notify({
          title: '提示',
          message: "至少选择一条记录！",
          type: 'warning'
        });
        return
      }
      for(let choice of this.selectChoice){
        ids.push(choice.id);
      }
      self.handleDelete(ids);
    },

    handleDelete(ids){
      let self = this;
      self.$confirm('确定删除该信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self.$http({
          url: "/drug/log/deleteBatchLog",
          method: "post",
          data: JSON.stringify({ids:ids}),
          dataType: 'json',
          contentType: "application/json",
        }).then(resp => {
          if (resp.success) {
            self.getList();
            self.$notify({
              title: '提示',
              message: "删除成功！",
              type: 'success'
            });
            return
          }
          self.$notify({
            title: '提示',
            message: "操作失败，请联系管理员！",
            type: 'error'
          });
        });
      });
    }

  },
}
</script>


<style lang="scss" scoped>
.el-form-no {
  text-align: right;
  font-size: 18px;
  color: #cb0000;
}
</style>
